
import java.util.Comparator;
import java.util.Map;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author dttung
 */
public class ScoreComparator implements Comparator<Object>{
    Map theMaptoSort;
    public ScoreComparator(Map theMap) {
        this.theMaptoSort = theMap;
    }
    @Override
    public int compare(Object team1, Object team2) {
        String score1 = (String)theMaptoSort.get(team1);
        String score2 = (String)theMaptoSort.get(team2);
        
        int winpos = score1.indexOf("|");        
        //int win = Integer.valueOf(score1.substring(0, winpos));
        int drawpos = score1.indexOf("|", winpos + 1);
        //int draw = Integer.valueOf(score1.substring(winpos + 1, drawpos));
        int loosepos = score1.indexOf("|", drawpos + 1);
        //int loose = Integer.valueOf(score1.substring(drawpos + 1, loosepos));
        int pointpos = score1.indexOf("|", loosepos + 1);
        int point1 = Integer.valueOf(score1.substring(loosepos + 1, pointpos));
        int diffpos = score1.indexOf("|", pointpos + 1);
        float currdiff1 = Float.valueOf(score1.substring(pointpos + 1, diffpos));
        float curryff1 = Float.valueOf(score1.substring(diffpos + 1, score1.length()));
        
        winpos = score2.indexOf("|");        
        //win = Integer.valueOf(score2.substring(0, winpos));
        drawpos = score2.indexOf("|", winpos + 1);
        //draw = Integer.valueOf(score2.substring(winpos + 1, drawpos));
        loosepos = score2.indexOf("|", drawpos + 1);
        //loose = Integer.valueOf(score2.substring(drawpos + 1, loosepos));
        pointpos = score2.indexOf("|", loosepos + 1);
        int point2 = Integer.valueOf(score2.substring(loosepos + 1, pointpos));
        diffpos = score2.indexOf("|", pointpos + 1);
        float currdiff2 = Float.valueOf(score2.substring(pointpos + 1, diffpos));
        float curryff2 = Float.valueOf(score2.substring(diffpos + 1, score2.length()));
        
        if (point1 < point2) return 1;
        if (point2 < point1) return -1;
        if (point1 == point2)
        {
            if (currdiff1 < currdiff2) return 1;
            if (currdiff1 > currdiff2) return -1;
            if (currdiff1 == currdiff2)
            {
                if (curryff1 < curryff2) return 1;
                else return -1;
            }
        }        
        return -1;
    }
        
}
